/*
    api:"删除公司信息"
    name:"陈小洋"
    time：2021.1.24
* */
const Company = require('../../../control/Company/Company')
const tools = require('../../../tools/public');
/**
 * @api {post} /company/delCompany 3.删除公司
 * @apiGroup Company
 *
 * @apiParam {String} CompanyId 公司id(删除多个用逗号隔开)
 *
 * @apiParamExample {json} Request-Example
 *{
 *
 *}
 * @apiSuccessExample  {json} Response-Example
 * {
 *   "code": 200,
 *   "msg": "删除成功！"
 *   }
 */
module.exports = async function (req, res, next) {
    let {CompanyId} = req.body,
        result = null;
    try {
        if (!CompanyId) return res.send(tools.ReturnData(204, '参数错误,请认真阅读接口文档！'));
        let _ids = CompanyId.split(','), _idsLength = _ids.length;
        if (_idsLength > 1) { // 删除多个
            let valueList = []
            for (let i = 0; i < _idsLength; i++) {
                valueList.push({_id: _ids[i]})
            }
            result = await Company.Del_Many_ById(valueList);
        } else { // 只删除一个
            result = await Company.Del_One_ById(CompanyId);
        }
        res.send(tools.ReturnData(200, '删除成功！', result));
    } catch (e) {
        console.log(e)
        return res.send(tools.ReturnData(500, '系统内部错误！'));
    }
};